import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/pages/navi_page.dart';
import 'package:flutter_app/pages/tree_page.dart';
import 'package:flutter_app/res/colours.dart';

class SeriesPage extends StatefulWidget {
  @override
  _SeriesState createState() {
    return _SeriesState();
  }
}

class _SeriesState extends State<SeriesPage>
    with SingleTickerProviderStateMixin {
  List<String> _abs = ['体系', '导航'];
  TabController _tabController;
  List<Widget> _pageList = [TreePage(), NaviPage()];

  //tabBar联动
  PageController _pageController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _abs.length, vsync: this);
    _pageController = PageController(initialPage: 0);
    _tabController.addListener(() {
      if (_tabController.indexIsChanging) {
        _pageController.animateToPage(_tabController.index,
            duration: Duration(milliseconds: 300), curve: Curves.decelerate);
      }
    });
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          centerTitle: true,
          // automaticallyImplyLeading: false,
          // leading: Icon(Icons.arrow_back),
          title: Text(
            '系列知识',
            style: TextStyle(color: Colors.black, fontSize: 16),
          ),
          bottom: TabBar(
            labelColor: Colors.black,
            unselectedLabelColor: Colors.black,
            controller: _tabController,
            indicatorColor: Colours.ff0692ff,
            indicatorSize: TabBarIndicatorSize.tab,
            indicatorWeight: 2.0,
            physics: const NeverScrollableScrollPhysics(),
            // 禁止滑动
            tabs: List.generate(
                _abs.length,
                (index) => Padding(
                      padding: EdgeInsets.all(15),
                      child: Text(_abs[index], style: TextStyle(fontSize: 15)),
                    )),
          ),
        ),
        body: PageView(
          controller: _pageController,
          children: _pageList,
          onPageChanged: (position) {
            _tabController.index = position;
          },
        ));
  }
}
